﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DatabaseCompare.Model
{

    /// <summary>
    /// 表信息.
    /// </summary>
    public class TableInfo : CompareAbleWithSubList<ColumnInfo>, ICloneable
    {


        #region ICloneable 成员

        public object Clone()
        {
            // 浅层克隆,
            TableInfo newTableInfo = this.MemberwiseClone() as TableInfo;

            // 重新克隆 列信息.
            if(newTableInfo.SubList != null) {

                newTableInfo.SubList = new List<ColumnInfo>();

                foreach (ColumnInfo col in this.SubList)
                {
                    newTableInfo.SubList.Add(col.Clone() as ColumnInfo);
                }
            }

            // 返回.
            return newTableInfo;
        }

        #endregion


        public override string ToString()
        {
            StringBuilder buff = new StringBuilder();
            buff.Append("表[");
            buff.AppendFormat("表名={0};", Name);
            buff.AppendFormat("备注/说明信息.={0};", Comment);
            buff.Append("列List={");
            if (SubList != null)
            {
                buff.AppendLine();
                for (int i = 0; i < SubList.Count; i ++)
                {
                    ColumnInfo column = SubList[i];
                    buff.AppendFormat("    列{0}={1}", i + 1, column);
                    buff.AppendLine();
                }
            }
            buff.Append("}");
            buff.Append("]");
            return buff.ToString();
        }
    }
}
